package controller

import (
	"git.900sui.cn/kc/apiPay/common/logics"
	_const "git.900sui.cn/kc/apiPay/lang/const"
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/rpcinterface/interface/order"
	"github.com/gin-gonic/gin"
	"strconv"
)

//获取银联用户标识

type XindaluaPayController struct {
	functions.Controller
}

const choseTypeField = "choseType"
const orderSnField = "orderSn"
const cidField = "cid"

func (t *XindaluaPayController) Prepare(ctx *gin.Context) {
	//请求校验
	choseType := t.Input.Post(choseTypeField).String()
	if len(choseType) == 0 {
		t.Output.Error(_const.ChoseTypeIsEmpty)
		return
	}
	//订单号
	orderSn := t.Input.Post(orderSnField).String()
	if len(orderSn) == 0 {
		t.Output.Error(_const.OrderSnIsEmpty)
		return
	}
	//地区信息cid
	cid := t.Input.Post(cidField).String()
	if len(cid) == 0 {
		t.Output.Error(_const.CidIsEmpty)
		return
	}
	ctx.Set(choseTypeField, choseType)
	ctx.Set(orderSnField, orderSn)
	ctx.Set(cidField, cid)
	t.Controller.Prepare(ctx)
}

func (t *XindaluaPayController) PayUnionder() {
	utils.Logerr.Printf("当前选择类型: choseType: %s, 订单号: %s", t.Ctx.GetString(choseTypeField), t.Ctx.GetString(orderSnField))
	chose_type, _ := strconv.Atoi(t.Ctx.GetString(choseTypeField))
	switch chose_type {
	case order.CHOSE_PAY_TYPE_XINDALU_WX, order.CHOSE_PAY_TYPE_WX:
		new(logics.WxpayLogic).Do(t.Controller, orderSnField, cidField)
	case order.CHOSE_PAY_TYPE_XINDALU_ALI, order.CHOSE_PAY_TYPE_ALI:
		new(logics.AlipayLogic).Do(t.Controller, orderSnField, cidField)
	case order.CHOSE_PAY_TYPE_XINDALU_YINLIAN:
		new(logics.YinlianPayLogic).Do(t.Controller, orderSnField, cidField)
	}
	utils.Logerr.Printf("请求结束")
}
